package com.hxx.day4;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;

public class TestDemo5 {
    public static void main(String[] args) {
        int[] data = {3,1,6,2,5};
        for (int i=data.length-1; i>0; i--) {
            for (int j=0; j<i; j++) {
                if (data[j] > data[j+1]) {
                    int temp = data[j];
                    data[j]	= data[j+1];
                    data[j+1] = temp;
                }
            }
        }
    }

    @Test
    public void test1() {
        int[] data = {3,1,6,2,5};
        //排序
        Arrays.sort(data);
        for (int index = 0; index < data.length; index++) {
            System.out.println(data[index]);
        }
        System.out.println("----------");
        //折半查找
        int index = Arrays.binarySearch(data, 3);
        System.out.println(index);
    }

    @Test
    public void test2() throws Exception{
        InputStream in = new FileInputStream("d:/zmx/one.txt");
        OutputStream out = new FileOutputStream("d:/zmx/two.txt");

        byte[] buf = new byte[1024];
        while (in.read(buf) != -1) {
            out.write(buf);
        }
        out.flush();
        out.close();
        in.close();
    }

}




















